
class Solution {
public:
    string convert(string s, int numRows) {
        if (numRows == 1) return s;
        std::vector<std::string> rows(numRows);
        int currentRow = 0;
        int step = -1;

        for (char c : s) {
            rows[currentRow].push_back(c);
            if (currentRow == 0 || currentRow == numRows - 1) {
                step = -step;
            }
            currentRow += step;
        }

        std::string result;
        for (const std::string& row : rows) {
            result += row;
        }
        return result;
    }
};